package com.link.linkupjavaweb.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.link.linkupjavaweb.entity.GameRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 游戏记录Mapper接口
 */
@Mapper
public interface GameRecordMapper extends BaseMapper<GameRecord> {
    
    /**
     * 查询用户的游戏记录
     */
    @Select("SELECT * FROM tb_game_record WHERE user_id = #{userId} AND game_type = 1 ORDER BY create_time DESC LIMIT #{limit}")
    List<GameRecord> selectUserGameRecords(@Param("userId") Long userId, @Param("limit") Integer limit);
    
    /**
     * 统计用户总游戏次数
     */
    @Select("SELECT COUNT(*) FROM tb_game_record WHERE user_id = #{userId} AND game_type = 1")
    Integer countUserGames(@Param("userId") Long userId);
    
    /**
     * 查询用户最高分
     */
    @Select("SELECT MAX(score) FROM tb_game_record WHERE user_id = #{userId} AND game_type = 1")
    Integer selectUserMaxScore(@Param("userId") Long userId);
}

